package com.das.mechanic_base.mvp.presenter.maintain;

import com.das.mechanic_base.base.X3BasePresenter;
import com.das.mechanic_base.bean.maintain.MainTainPlanBean;
import com.das.mechanic_base.bean.maintain.UpdateMainTainPlan;
import com.das.mechanic_base.mapi.api.NetWorkHttp;
import com.das.mechanic_base.mapi.response.HttpCallBack;
import com.das.mechanic_base.mapi.schedulers.RxSchedulersHelper;
import com.das.mechanic_base.mvp.contract.maintain.X3OrginFactoryPlanContract;

import java.util.ArrayList;
import java.util.List;

public class X3OrginFactoryPresenter extends X3BasePresenter<X3OrginFactoryPlanContract.View> implements X3OrginFactoryPlanContract.Presenter {

    @Override
    public void getMainTainPlanList(long carId) {
        NetWorkHttp.getApi().listMaintenanceServcieByCarId(carId)
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .compose(mView.bindToLife())
                .subscribe(new HttpCallBack<ArrayList<MainTainPlanBean>>() {
                    @Override
                    protected void onDone(ArrayList<MainTainPlanBean> bean) {
                        mView.onMainTainPlanSuccess(bean);
                    }

                    @Override
                    protected void NoNetCallBack() {
                        super.NoNetCallBack();
                    }

                    @Override
                    protected void showError(String error) {
                    }
                });
    }

    /**
     * 保养计划
     */
    @Override
    public void updateMainTainPlan(UpdateMainTainPlan bean) {
        NetWorkHttp.getApi().updateMaintenanceServcie(bean)
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .compose(mView.bindToLife())
                .subscribe(new HttpCallBack<Object>() {
                    @Override
                    protected void onDone(Object o) {
                        mView.updateMainTainPlanSuccess();
                    }

                    @Override
                    protected void showError(String error) {
                        mView.updateMainTainPlanFail(error);
                    }
                });
    }
}
